﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using System.Diagnostics;
using LensflareAIContest;

namespace LensflareAIContest {
    public class AIKamikaze : AI {
        public override void TimeElapsed(float secondsSinceLastTick, float secondsTotal) {
            //Oh, it's time to DIEEEEEEE!!!!
        }

        public override Vector2 ThrustForUnit(int index) {
            //all units move into the direction of the enemy heart:
            Random random = new Random();
            Vector2 randomOffset = new Vector2((float)random.NextDouble() * 2.0f - 1.0f, (float)random.NextDouble() * 2.0f - 1.0f);
            randomOffset *= 0.1f;
            Vector2 thrust = new Vector2(Info.HeartInfoForTeamIndex(EnemyTeamIndex).Position.X, 0);
            thrust.Normalize();
            return thrust + randomOffset;
        }

        public override Vector2? PreparedShotForUnit(int index) {
            var myUnits = Info.UnitsInfoForTeamIndex(TeamIndex);
            var enemyUnits = Info.UnitsInfoForTeamIndex(EnemyTeamIndex);
            Debug.Assert(myUnits != null && enemyUnits != null);

            //shoot at the enemy heart:
            var enemyHeart = Info.HeartInfoForTeamIndex(EnemyTeamIndex);
            if (enemyHeart != null) {
                if (enemyHeart.Health > 0) {
                    Vector2 posOfMyCurrentUnit = myUnits[index].Position;
                    Vector2 direction = enemyHeart.Position - posOfMyCurrentUnit;
                    return direction;
                } else {
                    return null; //it's dead. let it rest in peace.
                }
            } else {
                return null;
            }
        }

        public override String GetName() {
            return "Kamikaze 1.0";
        }
    }
}
